/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests;

import Utilities.Constants.VirtualResourceType;
import Utilities.Functions;

/**
 * Instances of this class are used for requesting permissions for specified actions
 * on virtual resources from the Permissions manager.
 *
 * @see Managers.PermissionsManager
 *
 * @author Angel Sanadinov
 */
public class AuthorizationRequest extends RequestBean
{
    private VirtualResourceType affectedResourceType;   //the type of resource that will be affected by the requested action
    private String affectedResourceId;  //the UUID of the affected resource

    /**
     * Constructs a new request object using the specified data. <br><br>
     *
     * <b>Note:</b> <i>Once constructed, the object cannot be modified!</i>
     *
     * @param userId the id of the requestor
     * @param serverId the id of the server on which the affected resource resides
     * @param actionId the id of the requested action
     * @param affectedResourceType the type of the requested resource
     * @param affectedResourceId the UUID of the affected resource
     *
     * @see Managers.Constants Resource Types
     */
    public AuthorizationRequest(int userId, int serverId, int actionId, VirtualResourceType affectedResourceType, String affectedResourceId)
    {
        super(userId, serverId, actionId);
        this.affectedResourceType = affectedResourceType;
        this.affectedResourceId = affectedResourceId;
    }

    /**
     * Checks the validity of the object. <br><br>
     *
     * This object is valid only when all data supplied when constructing it is
     * valid.
     *
     * @return <code>true</code> if the object is valid or <code>false</code> otherwise
     */
    @Override
    public boolean isValid()
    {
        if(isRequestorIdValid() && isServerIdValid() && isRequestedActionValid()
                && affectedResourceType != null
                && affectedResourceType != VirtualResourceType.INVALID
                && Functions.isUUIDValid(affectedResourceId))
            return true;
        else
            return false;
    }

    /**
     * Retrieves the type of the affected resource.
     *
     * @return the resource type
     *
     * @see Managers.Constants Resource Types
     */
    public VirtualResourceType getAffectedResourceType()
    {
        return affectedResourceType;
    }

    /**
     * Retrieves the UUID of the affected resource.
     *
     * @return the UUID of the resource
     */
    public String getAffectedResourceId()
    {
        return affectedResourceId;
    }

    /**
     * This method does nothing, as this object is immutable.
     *
     * @param requestedAction -
     */
    @Override
    public void setRequestedAction(int requestedAction){}

    /**
     * This method does nothing, as this object is immutable.
     *
     * @param serverId -
     */
    @Override
    public void setServerId(int serverId){}

    /**
     * This method does nothing, as this object is immutable.
     *
     * @param requestorId -
     */
    @Override
    public void setRequestorId(int requestorId){}

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (affectedResourceType,affectedResourceId)".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return AuthorizationRequest.class.getSimpleName() + ": ("
                + affectedResourceType + "," + affectedResourceId + ")";
    }
}
